
#include "i2c_master_poll.h"
#include "8025T.h"
 

@inline void 	RTC8025T_operinit(u8 n )
{
	SLAVE_ADDRESS = 0x64/2;
	set_tout_ms(n);
	cMemAddr = 0;
}	


u8  Rtc8025T_Read( u8  *datap  , u8 cAddr , u8 len )
{
 
 
	RTC8025T_operinit(len);
	
	I2C_ReadRegister1( cAddr  , len , (u8 *)datap);
	if(!(tout()) )
{
	 I2C_Init();
			return 1;
		}
	return  (!(	_I2C_err	)) ;
		
	
}

u8   Rtc8025T_write( u8  *datap , u8 cAddr , u8 clen  )
{
	
	RTC8025T_operinit(clen);
	
	I2C_WriteRegister1( cAddr  , clen, datap);
	if(!(tout()) )
{
	 I2C_Init();
			return 1;
		}
	return  (!(	_I2C_err	)) ;
	
}

 
 
u8  Rtc8025T_ReadTime(  struct  ST8025T_TIME  *datap )
{
  return Rtc8025T_Read( (u8 *)datap  , _cn_st8025_time_addr , sizeof( struct ST8025T_TIME ) );
}

u8 Rtc8025T_WriteTime(  struct  ST8025T_TIME  *datap )
{
	return Rtc8025T_write( (u8 *)datap  , _cn_st8025_time_addr , sizeof( struct ST8025T_TIME )  );
}
	

u8  Rtc8025T_ReadCon( struct  ST8025T_CON *datap )
{
	return Rtc8025T_Read( (u8 *)datap  , _cn_st8025t_con_addr , sizeof( struct  ST8025T_CON) );
}
	
u8  Rtc8025T_WriteCon( struct  ST8025T_CON *datap )
{
	return Rtc8025T_write( (u8 *)datap  , _cn_st8025t_con_addr , sizeof( struct  ST8025T_CON) );
}
	
 



u8 RTC8025T_config(RTC8025T_OPER_TypeDef  n )
{
	
	struct  ST8025T_CON  sttemp ;
	struct  ST8025T_CON  sttemp1 ;
	u8 i;
	i =   Rtc8025T_ReadCon( &sttemp );
	if ( i ) return i ;
	
	if (  RTC8025T_SECPLUSE_EN  ==  n )
	{
		 sttemp.cExtendReg.bUsel = 0 ;
		 sttemp.cFlagReg.bUf = 0;
		 sttemp.cConReg.bUie=1;
		 sttemp.cConReg.b2_Csel =1;
  }
	else
		if ( RTC8025T_SECPLUSE_DIS == n )
		{
				sttemp.cConReg.bUie=0; 
		}
		  sttemp.cExtendReg.bTest = 0 ;
	return   Rtc8025T_WriteCon( &sttemp ) ;
	 i =   Rtc8025T_WriteCon( &sttemp ) ; 
	 i =  Rtc8025T_ReadCon(&sttemp1);
	 
	 if (   *((u32 *)&sttemp) ==  *((u32 *)&sttemp1)  )
			return 1;
		else
			return 0;
	 
}
